using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Utils;

public class Scythe01 : Weapon
{
    public Animator animator;
    public Melee melee;
    public float cd = 0.4f;
    public float timing;
    public Collider2D activeCollider;

    private void Start()
    {
        effectAudio.clip = GameController.Instance().audioCtr.GetMusic("Melee/swing_02");
        melee = UITool.GetComponent<Melee>("Melee/Collider", gameObject);
        melee.atk = (int) attack;
        animator = UITool.GetComponent<Animator>("Melee", gameObject);
        spriteRenderer = GetComponentInChildren<SpriteRenderer>();
        self = PrefabRoot.Scythe01;
    }

    private void Update()
    {
#if UNITY_STANDALONE_WIN
        CheckKeysState();
        ChangeOrientation();
#endif
    }

    // public override void ResetForward()
    // {
    //     
    // }

    protected override void ChangeOrientation()
    {
        if (tag.Equals("Player") && GameController.Instance().FSM.CurPlayerState == PlayerState.NotFight)
        {
            x = Input.GetAxis("Horizontal");
            if (x > 0) transform.rotation = quaternions[1];

            if (x < 0) transform.rotation = quaternions[5];

        }
    }

    public override void ResetForward()
    {
        // transform.rotation = quaternions[1];
    }

    public override  void UpdateLookAt(Vector3 target)
    {
        if (transform.position.x > target.x)
        {
            transform.rotation = quaternions[5];
        }
        else if (transform.position.x < target.x)
        {
            transform.rotation = quaternions[1];
        }
    }

    public override void AttackButtonPress()
    {
        if (Time.timeScale != 0 && Time.time - timing >= cd && melee.canAttack)
        {
            if (GameController.Instance().FSM.CurPlayerState == PlayerState.Die)
            {
                return;
            }
            activeCollider.enabled = true;
            melee.canAttack = false;
            timing = Time.time;
            animator.Play("Attack");
            effectAudio.Play();
        }
    }
    
}